<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../style/css/user/center.css">
    <link rel="stylesheet" type="text/css" href="../../style/css/back/style.css">
    <script src="../../style/js/jquery-1.8.3.js" type="text/javascript"></script>
    <script src="../../style/js/ajaxfileupload.js"></script>
    <script type="text/javascript">
        $(function () {
            $.get("../../user/getUserCollect", function (res) {
                if (res.code === 500) {
                    alert(res.msg);
                } else if (res.code === 202) {
                    alert("登录失效,请重新登录")
                } else {
                    var str = ""
                    for (let i = 0; i < res.data.length; i++) {
                        console.log(res.data.length)
                        str += "<tr align='center'>";
                        str += "<td id='numTd'>" + (i + 1) + "</td>"
                        str += "<td>" + res.data[i].news.title + "</td>"
                        str += "<td>" + (new Date(res.data[i].news.publishTime)).toLocaleString() + "</td>"
                        str += "<td><a onclick='deleteCollect(" + res.data[i].news.id + ")' href='javaScript:void(0)'>取消收藏</a> \t\t\t\t " +
                            "<a onclick='deleteCollect(" + res.data[i].news.id + ")' href='javaScript:void(0)'>查看</a>"
                        str += "</tr>"
                    }
                    $("#collectTable").append(str);
                }
            })
        })

        function deleteCollect(newsId) {
            if (confirm("确定要取消该收藏吗?")) {
                $.get("../../user/deleteCollect", {collectNewsId: newsId}, function (res) {
                    if (res.code === 500) {
                        alert(res.msg);
                    } else if (res.code === 202) {
                        alert("登录失效,请重新登录")
                    } else {
                        location.reload();
                    }
                })
            }
        }


    </script>
</head>
<body>
<div class="public_m1">
    <div class="public_m2">收藏管理</div>
    <!--数据列表 -->
    <table class="tablelist" id="collectTable" style="width: 888px">
        <tr>
            <th>序号<i class="sort"></i></th>
            <th>新闻标题</th>
            <th>推送时间</th>
            <th>操作</th>
        </tr>
    </table>
</div>
</body>
</html>
